package net.uman.web.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class FlexDate {
	public static String getDate(Date trialTime) {
		Calendar calendar = new GregorianCalendar();
		if(trialTime==null){
			trialTime=new Date(System.currentTimeMillis());
		}
		String ret="";
		
		calendar.setTime(trialTime);

		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
		ret=year + "-" ;
		if(month<10){
			ret=ret+"0"+month+"-";
		}else{
			ret=ret+month+"-";
		}
		if(day_of_month<10){
			ret=ret+"0"+day_of_month;
		}else{
			ret=ret+day_of_month;
		}
		return ret;
	}
	/**
	 * 返回日期格式为YYYY-MM-DD HH:MM:SS
	 * @return
	 */
	public static String getFullDate() {
		String ret="";
		Date trialTime=new Date(System.currentTimeMillis());
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(trialTime);

		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int minute = calendar.get(Calendar.MINUTE);
		int second = calendar.get(Calendar.SECOND);
		ret=year + "-" ;
		if(month<10){
			ret=ret+"0"+month+"-";
		}else{
			ret=ret+month+"-";
		}
		if(day_of_month<10){
			ret=ret+"0"+day_of_month;
		}else{
			ret=ret+day_of_month;
		}
		ret=ret+ " ";
		if(hour<10){
			ret=ret+"0"+hour+"-";
		}else{
			ret=ret+hour+":";
		}
		if(minute<10){
			ret=ret+"0"+minute+":";
		}else{
			ret=ret+minute+":";
		}
		if(second<10){
			ret=ret+"0"+second;
		}else{
			ret=ret+second;
		}
		return ret;
	}
}
